# -*- coding: utf-8 -*-

import datetime
from google.appengine.ext import db

# Shop Information
class ShopInfo(db.Model):
    '''
    Key name field is the same as nick, but start with 'favshop-'
    '''
    sid = db.StringProperty()
    cid = db.StringProperty()
    nick = db.StringProperty()
    title = db.StringProperty()
    desc = db.TextProperty()
    bulletin = db.TextProperty()
    pic_path = db.StringProperty()
    create = db.DateTimeProperty()
    modified = db.DateTimeProperty()
    last_update = db.DateTimeProperty(auto_now=True)

# Shop Subscription
class SubscriptionInfo(db.Model):
    '''
    Key name is the same as nick, but start with 'favshop-'
    '''
    nick = db.StringProperty()
    last_update_time = db.DateTimeProperty(default=datetime.datetime(1970,1,1,0,0))
    fetchsop_update_time = db.DateTimeProperty(default=datetime.datetime(1970,1,1,0,0))
    wangpu = db.TextProperty()
    recommendation = db.TextProperty()    

# Current Updating Information
class CurrentUpdatingInfo(db.Model):
    nick = db.StringProperty(default='')
    page_number = db.IntegerProperty(default=0)

# Goods Information
class GoodsInfo(db.Model):
    '''
    Key name is goods' iid, but start with 'favshop-'
    '''
    iid = db.StringProperty()
    title = db.StringProperty()
    nick = db.StringProperty()
    type = db.StringProperty()
    cid = db.StringProperty()
    pic_path = db.StringProperty()
    delist_time = db.DateTimeProperty()
    price = db.FloatProperty()
    post_fee = db.FloatProperty()

# Change Event of One Shop
class ChangeEvent(db.Model):
    title = db.StringProperty()
    summary = db.StringProperty()
    content = db.TextProperty()
    nick = db.StringProperty()
    goods_info = db.ReferenceProperty(GoodsInfo)
    timestamp = db.DateTimeProperty(auto_now_add=True)

# User Information from SIP Platform
class UserInfo(db.Model):
    '''
    Kye name is the same as nick, but start with 'favshop-'
    '''
    nick = db.StringProperty()
    created = db.DateTimeProperty()
    last_visit = db.DateTimeProperty()
    location_city = db.StringProperty()
    location_state = db.StringProperty ()
    buyer_good_num = db.IntegerProperty()
    buyer_level = db.IntegerProperty()
    buyer_score = db.IntegerProperty()
    buyer_total_num = db.IntegerProperty()
    seller_good_num = db.IntegerProperty()
    seller_level = db.IntegerProperty()
    seller_score = db.IntegerProperty()
    seller_total_num = db.IntegerProperty()
    last_update = db.DateTimeProperty(auto_now=True)

# Subscription Update Log
class SubUpdateLog(db.Model):
    '''
    Key name is NOT nick. 
    '''
    nick = db.StringProperty()
    update_timestamp = db.DateTimeProperty(auto_now_add=True)
    log_msg = db.StringProperty()
    log_status = db.BooleanProperty(default=False)
    
# Favshop User
class FavshopUser(db.Model):
    '''
    Key name is gmail/taobao user id, start with 'favshop-'
    '''
    username = db.StringProperty()
    sub_list = db.StringListProperty() # shop nick list
